<?php
/**
 * @file
 * Context redirect reaction plugin for Context API.
 */

class context_login_redirect_reaction extends context_reaction {
  /**
   * Implements options_form().
   */
  public function options_form($context) {

    $values = $this->fetch_from_context($context);
    $form['#tree'] = TRUE;

    $form['status'] = array(
      '#title' => t('status'),
      '#type' => 'checkbox',
      '#default_value' => isset($values['status']) ? $values['status'] : 0
    );
    return $form;
  }

  /**
   * Implements execute().
   */
  public function execute() {

    $contexts = $this->get_contexts();

    foreach ($contexts as $context) {
      if (!empty($context->reactions[$this->plugin])) {
        if ($context->reactions[$this->plugin]['status']) {
          if(!user_is_logged_in()) {
            if(!empty($_SERVER["QUERY_STRING"]))
              linkmed_sub_user_redirect_to_login($_GET['q'] . '?' . $_SERVER["QUERY_STRING"], '请先进行登录');
            else
              linkmed_sub_user_redirect_to_login($_GET['q'], '请先进行登录');
          }
        }
      }
    }
  }
}
